﻿<UserControl x:Class="LaunchPad.Core.Controls.NodeControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:core="clr-namespace:LaunchPad.Core"
             xmlns:local="clr-namespace:LaunchPad.Core.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="182" d:DesignWidth="474">
    <UserControl.Resources>
        <DrawingBrush x:Key="RedDiagonalBrush" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,25,25">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Geometry="M0,25 L25,0" Brush="Red">
                        <GeometryDrawing.Pen>
                            <Pen Brush="Red" />
                        </GeometryDrawing.Pen>
                    </GeometryDrawing>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <Style TargetType="{x:Type Expander}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=IsHovered}" Value="True">
                    <Setter Property="IsExpanded" Value="True" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="{x:Type local:NodeControl}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=ConnectionState}" Value="Disconnected">
                <Setter Property="Background" Value="{StaticResource RedDiagonalBrush}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=IsHovered}" Value="True">
                    <Setter Property="Background" Value="LightSteelBlue" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Grid MinHeight="14">
                            <Rectangle Name="PART_Track" Stroke="#FFEBEBEB" StrokeThickness="2">
                                <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                        <GradientStop Offset="1" Color="#BB00FF00"/>
                                        <GradientStop Offset="0.3" Color="#BBFFFF00"/>
                                        <GradientStop Offset="0" Color="#BBFF0000"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <DockPanel Margin="0">
                                <Rectangle Name="PART_Indicator">
                                </Rectangle>
                                <Rectangle Name="Mask" MinWidth="{TemplateBinding Width}" Fill="#FFEBEBEB"/>
                            </DockPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <ObjectDataProvider MethodName="GetValues"
                        ObjectType="{x:Type sys:Enum}"
                        x:Key="EffectPortValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="core:EffectPort" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Content="Node" HorizontalAlignment="Right" Margin="4" Name="label1" VerticalAlignment="Top" FontWeight="Bold"   />
        <DockPanel Grid.Column="1" HorizontalAlignment="Stretch" Width="Auto">
            <TextBox Margin="6" Text="{Binding Name}" HorizontalAlignment="Stretch" VerticalAlignment="Center" MinWidth="100" DockPanel.Dock="Left" />
            <ProgressBar HorizontalAlignment="Right" DockPanel.Dock="Right" VerticalAlignment="Center" Width="54" Value="{Binding SignalStrength}" Margin="6" ToolTip="Signal Strength" BorderBrush="#75000000" Grid.Column="1" Maximum="92" />
            <TextBlock Text="{Binding ConnectionState}" TextAlignment="Right" DockPanel.Dock="Right" Margin="6" VerticalAlignment="Center" />
        </DockPanel>

        <Label Content="SN" FontWeight="Bold" Margin="6" VerticalAlignment="Center" Grid.Row="1" HorizontalAlignment="Right" />
        <DockPanel Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" Width="Auto">
            <TextBlock Text="{Binding Path=SerialNumber.Value}" Margin="6" VerticalAlignment="Center" FontWeight="Bold" MinWidth="100" DockPanel.Dock="Left" />
            <TextBlock Text="Address" FontWeight="Bold" Margin="6" VerticalAlignment="Center" />
            <TextBlock FontWeight="Bold" Margin="6" Text="{Binding Path=ShortAddress.Value}" VerticalAlignment="Center" />
            <TextBox Margin="6" Text="{Binding Path=Location.Y, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" DockPanel.Dock="Right" />
            <Label Content="Y" FontWeight="Bold" Margin="6" VerticalAlignment="Center" DockPanel.Dock="Right"/>
            <TextBox Margin="6" Text="{Binding Path=Location.X, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" DockPanel.Dock="Right"/>
            <Label Content="X" FontWeight="Bold" VerticalAlignment="Center" DockPanel.Dock="Right" HorizontalAlignment="Right"/>

        </DockPanel>
            <Expander Header="Effects" HorizontalAlignment="Stretch" Margin="4" Name="timelineExpander" VerticalAlignment="Stretch" Grid.Row="2" Grid.Column="1">
          <Grid>
            <DataGrid ItemsSource="{Binding Path=Effects}" Name="effectsDataGrid" AutoGenerateColumns="False" CanUserAddRows="False" Margin="37,6,6,6">
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="Port" >
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                    <ComboBox ItemsSource="{Binding Source={StaticResource EffectPortValues}}" 
                                              Text="{Binding Path=Port, Mode=TwoWay, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" 
                                              FontWeight="Bold" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                                              VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Effect" Width="*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <local:EffectControl></local:EffectControl>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    </DataGrid.Columns>
            </DataGrid>
                <Button Content="+" Height="23" HorizontalAlignment="Left" Margin="6,6,0,0" Name="addButton" VerticalAlignment="Top" Width="25" Click="addButton_Click" />
            </Grid>
        </Expander>
    </Grid>
</UserControl>
